package com.zzl.study.nacos.config;

import com.zzl.study.nacos.condition.ConditionalOnNacosMultiDiscoveryEnabled;
import com.zzl.study.nacos.discovery.NacosServiceMultiDiscovery;
import com.zzl.study.nacos.discovery.reactive.NacosReactiveMultiDiscoveryClient;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration;
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Nacos多注册中心响应式服务发现客户端自动配置类
 *
 * @author: zhangzl
 * @date: 2025/7/16 15:16
 * @version: 1.0
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnDiscoveryEnabled
@ConditionalOnReactiveDiscoveryEnabled
@ConditionalOnNacosMultiDiscoveryEnabled
@AutoConfigureBefore({ReactiveCommonsClientAutoConfiguration.class})
@AutoConfigureAfter({NacosMultiDiscoveryAutoConfiguration.class, ReactiveCompositeDiscoveryClientAutoConfiguration.class})
public class NacosReactiveMultiDiscoveryClientAutoConfiguration {

    /**
     * 向Spring容器注入一个Nacos多注册中心响应式服务发现客户端
     *
     * @param nacosServiceMultiDiscovery Nacos多注册中心服务发现对象
     * @return Nacos多注册中心响应式服务发现客户端
     */
    @Bean
    @ConditionalOnMissingBean
    public ReactiveDiscoveryClient nacosReactiveMultiDiscoveryClient(NacosServiceMultiDiscovery nacosServiceMultiDiscovery) {
        return new NacosReactiveMultiDiscoveryClient(nacosServiceMultiDiscovery);
    }

}
